#ifndef interface_h
#define interface_h

#include <game.h>


typedef struct interface_t
{
  enum {is_force, is_play, is_playother, is_quit} state;
  int depth_limit;  // max depth
  int time_limit;  // max milliseconds per move

  int tc_moves;  // moves left in the current time control
  int tc_time;  // time left (milliseconds) in the current time control
  int tc_otime;  // time left (milliseconds) for the opponent
  int increment;  // additional time per move (milliseconds)
  
  int show_think;
  game_t game;
  char prompt[80];
  int input;  // file descriptor
  int searching;

  int resignation_count;
} interface_t;


/*
 * Manage input commands.
 */
void interface_main_loop(interface_t* iface);

/*
 * Poll the input channel and execute a single command (if any).
 *
 * Returns 1 if some text has been parsed (which means that another
 * call to this function may also succeed). Returns 0 otherwise.
 */
int interface_handle_input(interface_t* iface);

/*
 * Initialize the interface structure.
 *
 * Call this function for each interface object before using
 * it. Returns 1 in case of success, 0 in case of error.
 */
int interface_init(interface_t* iface);

/*
 * Free the resources allocated by the interface object.
 */
void interface_cleanup(interface_t* iface);

/*
 * Copy an existing interface over another.
 *
 * Both interfaces must have been initialized. Returns 1 in case of
 * success, 0 in case of error.
 */
int interface_copy(const interface_t* src, interface_t* dst);

/*
 * Set the descriptor for the input channel used by the interface.
 *
 * Note that the descriptor is not acquired nor released by the
 * interface.
 */
void interface_set_input(interface_t* iface, int fd);



#endif  // interface_h
